
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">
    <title>log</title>
    <style>
    #log {width:500px; height: 500px;}
    .divLeft{ float: left; border: 1px solid; width:1250px;}
    .divRight{ float:right;border: 1px solid;width:400px; height:800px; z-index:99999;  overflow-y:scroll; }
        .divRight input { margin:2px;cursor: pointer;}
	.input_bg_red {background-color: red;}
	.input_bg_yellow {background-color: yellow;}
    </style>
	<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
	<script src="/Public/js/echarts.common.min.js"></script>
	<script>

		var anlsData = null;
	
	
    	function setTotalChart(chartData,xData){
    		var total = echarts.init(document.getElementById('total'));
    		var option = {
    			    title: {
    			        text: '总盈利'
    			    },
    			    tooltip: {trigger: 'axis'},
    			    xAxis: {
    		        	data:xData
    			    },
    			    yAxis: {
    			    	interval : 5,
    			        type: 'value'
    			    },
    	            
    			    series: [{
    			        name: '总盈利',
    			        type: 'line',
    			        showSymbol: false,
    			        hoverAnimation: false,
    			        data: chartData
    			    }
    			    
    			    ]
    			};
    		total.setOption(option);
    	}

		function setBmhpChart(chartData,lostData,bmcpData,xData,bmhpTimesChartData){
			var bmhp = echarts.init(document.getElementById('bmhp'));
			var option = {
				    title: {
				        text: $("#code").val()+'最高盈利'
				    },
				    tooltip: {trigger: 'axis'},
				    xAxis: {
			        	data:xData
				    },
				    yAxis: {
				    	interval : 5,
				        type: 'value'
				    },
				    color:[ '#c23531', '#749f83',  '#ca8622', '#bda29a', '#c4ccd3']
				    ,series: [
    					{
    				        name: '最高盈利',
    				        type: 'line',
    				        showSymbol: false,
    				        hoverAnimation: false,
    				        data: chartData
    				    },
    				    {
    				        name: '最高盈利少于5次数',
    				        type: 'line',
    				        showSymbol: false,
    				        hoverAnimation: false,
    				        data: bmhpTimesChartData
    				    },
    				    {
        			        name: '连赢',
        			        type: 'line',
        			        showSymbol: false,
        			        hoverAnimation: false,
        			        data: lostData
        			    },{
        			        name: '平仓盈利',
        			        type: 'line',
        			        showSymbol: false,
        			        hoverAnimation: false,
        			        lineStyle:{
            			        width:1,
								normal : {opacity:0.2}
            			    },
        			        data: bmcpData
        			    }
				    ]
				};
				bmhp.setOption(option);
		}
	
		function init(code){
				$.ajax({
					url:'/Anls/trade/getTradeLog?code='+code
					,dataType:'json'
					,success:function(data){
						if(!data && !data.length) return false;
						var bmhpChartData = [];
						var bmcpChartData = [];
						var lostChartData = [];
						var totalChartData = [];
						var bmhpTimesChartData = [];
						var xData = [];
						var total = 0;

						// 连输次数
						var lost = 0;
						// 最高盈利<N次数
						var bmhpTimes = 0;
						for(var i=0;i<data.length;i++){
							var log = JSON.parse(data[i]);
							//console.info(log.bwp);
							var date = log.buyCloseDate;
							dateNum = parseInt(date.replace(/\//g,""));
							if(dateNum<parseInt($("#inputDate").val())) continue;
							xData.push(date);
							total = total + log.bwp;
							//total = total.toFixed(2);
							var bmhp = log.bmhp > 100? 100:log.bmhp;
							if(log.buyWinPoint <0){
								if(lost>0){
									lost = -1;
								} else {
									lost--;
								}
							} else {
								if(lost<0){
									lost = 1;
								} else {
									lost++;
								}
							}
							if(bmhp<5){
								if(bmhpTimes>0){
									bmhpTimes = -1;
								} else {
									bmhpTimes--;
								}
							} else {
								if(bmhpTimes<0){
									bmhpTimes = 1;
								} else {
									bmhpTimes++;
								}
							}
							
							bmhpChartData.push(bmhp);
							lostChartData.push(lost);
							bmcpChartData.push(log.bwp);
							totalChartData.push(total.toFixed(2));
							bmhpTimesChartData.push(bmhpTimes);
						}
						setBmhpChart(bmhpChartData,lostChartData,bmcpChartData,xData,bmhpTimesChartData);
						setTotalChart(totalChartData,xData);
					}
				});
		}

		function anls(){
			var code = $("#code").val();
			init(code);
		}

		function changeCode(code){
			$("#code").val(code);
			anls();
		}

		function initAnlsData(){
			$.ajax({
				url:'/Anls/trade/getAnlsData'
				,dataType:'json'
				,success:function(data){
					if(!data) return false;
					anlsData = data;
					for(var code in data){
						var val = JSON.parse(data[code]);
						var html = "<input type='button' id='code_"+code+"' value='"+code+"' onclick=changeCode('"+code+"') />";
						$("#codeList").append(html);	
					}
				}
			});
		}
	
		$(function(){
			initAnlsData();
			initAnlsData();
			anls();
			//init('000007');
			$("#prevBtn").click(function(){
				var curVal = $("#code").val();
				var prevVal = $("#searchCodeList").find("input[value="+curVal+"]").prev().val();
				
				$("#code").val(prevVal);
				anls();
			});

			$("#nextBtn").click(function(){
				var curVal = $("#code").val();
				var nextVal = $("#searchCodeList").find("input[value="+curVal+"]").next().val();
				$("#code").val(nextVal);
				anls();
			});
		})
		
		function dataSearch(){
			if(!anlsData)return false;
			var loseLimitVal = $("#loseLimit").val();
			var highWinLtVal = $("#bmhpLimit").val();
			$("#searchCodeList").html("");
			for(var code in anlsData){
				var val = JSON.parse(anlsData[code]);
				var loseLimit = val.loseLimit.cur;
				var highWinLt = val.highWinLt.cur;
				if(loseLimit>loseLimitVal && highWinLt>highWinLtVal){
					console.info(highWinLt+","+highWinLtVal+"|"+(highWinLt>highWinLtVal));
					$("#code_"+code).css("background-color","red");
					var html = "<input class='input_bg_yellow' type='button' id='search_code_"+code+"' value='"+code+"' onclick=changeCode('"+code+"') />";
					$("#searchCodeList").append(html);	
				}
				/*
				if(highWinLt>highWinLtVal && highWinLtVal != 0){
					$("#code_"+code).css("background-color","yellow");
					var html = "<input class='input_bg_yellow' type='button' id='search_code_"+code+"' value='"+code+"' onclick=changeCode('"+code+"') />";
					$("#searchCodeList").append(html);	
				}
				*/
				
			}
		}
		
	</script>
  </head>

  <body>
  	<div class="divLeft">
      	<input type="text" id="code" value="600094" />
      	<input type="text" id="inputDate" value="20150000" />
      	<input type="button" id="btn" value="搜索" onclick="anls()" />
      	<input type="button" id="prevBtn" value="prev"  />
      	<input type="button" id="nextBtn" value="next"  />
      	&nbsp;&nbsp;|&nbsp;&nbsp;连输>loseLimit：<input style="width:30px" class='input_bg_yellow'  type="text" id="loseLimit" value="3" />
      	&nbsp;&nbsp;|&nbsp;&nbsp;最高少于bmhp：<input style="width:30px" class='input_bg_yellow'  type="text" id="bmhpLimit" value="3" />
      	<input type="button" id="btn" value="数据搜索" onclick="dataSearch()" />
    	<div id="bmhp" style="width: 1250px;height:400px;"></div>
    	<div id="total" style="width: 1250px;height:400px;"></div>
	</div>
	<div class="divRight" id="searchCodeList"></div>
	<div class="divRight" id="codeList"></div>
  </body>
</html>
